//
//  HWHeavyGameCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/24.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWHeavyGameCell: UICollectionViewCell {
    var logoImageView:UIImageView!
    var nameLabel:UILabel!
    var typeLabel:UILabel!
    var model:HWHomeTuiJianModel? {
        didSet {
            logoImageView.sd_setImage(with: URL(string: model?.icon ?? ""), completed: nil)
            nameLabel.text = model?.name
            typeLabel.text = model?.type
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWHeavyGameCell {
    private func initUI() -> Void {
        contentView.backgroundColor = .clear
        
        logoImageView = UIImageView()
        logoImageView.layer.cornerRadius = 15*widthScale
        logoImageView.layer.masksToBounds = true
        contentView.addSubview(logoImageView)
        
        nameLabel = HWLabel.createBoldLabel(title: "", color: "#333333", font: 14*widthScale)
        nameLabel.textAlignment = .center
        nameLabel.numberOfLines = 1
        contentView.addSubview(nameLabel)
        
        typeLabel = HWLabel.createLabel(title: "", color: "#888888", font: 9*widthScale)
        typeLabel.textAlignment = .center
        typeLabel.numberOfLines = 1
        contentView.addSubview(typeLabel)
        
    }
    
    private func initFrame() -> Void {
        
        logoImageView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(0)
            make.width.height.equalTo(65*widthScale)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(logoImageView.snp.bottom).offset(7*widthScale)
            make.height.equalTo(20*widthScale)
        }
        
        typeLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(nameLabel.snp.bottom)
            make.height.equalTo(13*widthScale)
        }
    }
}
